require "Common/define"
require "Logic/Config"
require "Net/send_Msg"
require "Net/friendHandler"
require "Common/functions"

UIPlayerShow = {};
HelperFunc.SetUIEnv(UIPlayerShow)
local this = UIPlayerShow;

this.LuaBehaviour = nil;
this.transform = nil;
this.gameObject = nil;

this.heroName = nil;
this.heroLevel = nil;
this.heroLove = nil;
this.heroPower = nil;
this.heroID = nil;
this.heroFormObj = {}
this.OtherPlayerID = 0
this.OtherData = nil
this.isload = false
this.btnaddFriend = nil;
this.btnpvchat = nil;
this.btnback = nil;
this.headIcon = nil;
this.titles = nil;
UIPlayerShow.sendForm = {}

this.Btn_BGClose = nil
this.Btn_PetMating = nil
this.Txt_PetName = nil
this.Model_Pet = nil
this.drawWrapper = nil
this.PetModelGO = nil
this.funcBack = nil;

this.btnGuildSetting = nil;
this.btn_membershipapplication = nil;
this.btn_amendmentnotice = nil;
this.btn_Informationsettings = nil;
this.btn_quittheguild = nil;
this.btn_blackbackground = nil;
this.managementController = nil;
this.positionController = nil;
this.memberTypeController = nil;
this.text_guildName = nil;
this.text_position = nil;
this.funcBattleBack = nil;--切磋战斗后返回页面的方法

local effect_mat = nil
local effect_mat2 = nil

function UIPlayerShow.Init(sendID, funcBack, isInCity, funcBattleBack)
    this.OtherData = sendID;
    this.funcBack = funcBack;
    this.isInCity = isInCity;
    this.funcBattleBack = funcBattleBack;
    local name, packageName = getUIName(PanelNames.UIPlayerShow);
    panelMgr:ShowUI(name, packageName, this.OnCreate, Config.useLocalUI);
end

--定义控件
function UIPlayerShow.OnCreate(obj)
    if not UIPackage.GetById("FUI/Emoji") then
        this.isNeedRemovePackage = true;
        AddUIPackageDepend(PanelNames.UIPlayerShow, "FUI/Emoji")
    end
    gameObject = obj;
    if (isload == false) then
        isload = true;
        heroName = obj:GetChild("HeroName");
        heroPower = obj:GetChild("power");
        heroLevel = obj:GetChild("level");
        heroLove = obj:GetChild("love");
        heroID = obj:GetChild("ID");
        btnCopy = obj:GetChild("copy");
        serverName = obj:GetChild("Text_ServerName")
        heroSex = obj:GetController("mainsex")
        btnaddFriend = obj:GetChild("btnaddFriend");
        btnBattle = obj:GetChild("btnBattle");
        btnpvchat = obj:GetChild("btnpvchat");
        btnback = obj:GetChild("btnback");

        btnGuildSetting = obj:GetChild("btnGuildSetting");
        local managerObj = obj:GetChild("Com_manager");
        text_guildName = obj:GetChild("Text_guildName");
        text_position = obj:GetChild("Text_position");
        this.btnPlayerkick = obj:GetChild("btnPlayerkick");
        managementController = obj:GetController("Managementofguildmembers");
        btn_membershipapplication = managerObj:GetChild("Btn_membershipapplication");
        btn_membershipapplication.title = getLanguage("CommonPop_Title41");
        btn_amendmentnotice = managerObj:GetChild("Btn_amendmentnotice");
        btn_amendmentnotice.title = getLanguage("GuildInvestment_1064")
        btn_Informationsettings = managerObj:GetChild("Btn_Informationsettings");
        btn_Informationsettings.title = getLanguage("GuildInvestment_1065");
        btn_quittheguild = managerObj:GetChild("Btn_quittheguild");
        btn_quittheguild.title = getLanguage("GuildInvestment_1066")
        this.btnPlayerkick.title = getLanguage("GuildInvestment_1066")
        btn_blackbackground = managerObj:GetChild("Btn_blackbackground");
        positionController = managerObj:GetController("positionController");
        memberTypeController = managerObj:GetController("memberType");
        memberType1Controller = obj:GetController("memberType");

        btn_BlackList = obj:GetChild("btnBlackList")
        txt_blackTxt = btn_BlackList:GetChild("title")
        if logicMgr.FriendManager.IsInBlack(OtherData.data.playerId) then
            txt_blackTxt.text = getLanguage("BlackListTips2")
        else
            txt_blackTxt.text = getLanguage("CommonPop_Title114")
        end

        this.isInCityController = obj:GetController("isInCity");
        this.emojiList = obj:GetChild("Emoji"):GetChild("emotionList");
        this.showEmojiController = obj:GetController("ifShowEmoji");
        headIcon = obj:GetChild("icon");
        this.Btn_BGClose = obj:GetChild("Btn_BGClose")
        this.Btn_PetMating = obj:GetChild("Btn_PetMating")
        this.Txt_PetName = obj:GetChild("Txt_PetName")

        this.Model_Pet = obj:GetChild("Model_Pet")
        this.Btn_ShowPetInfo = obj:GetChild("Btn_ShowPetInfo")
        this.ctrlFriend = obj:GetController("state")
        this.isMeController = obj:GetController("isMe")
        heroFormObj = {}
        for i = 1, 5 do
            local tempobj = obj:GetChild("heroPo" .. i);
            table.insert(heroFormObj, tempobj)
        end
        titles = {};
        for i = 1, 5 do
            table.insert(titles, obj:GetChild("Badge" .. i));
        end

        local effect = titles[1]:GetChild("Effect_Dwsg")
        local t = effect.displayObject.cachedTransform:Find("GoWrapper/effect_dwsg_SkeletonData")
        local anim = t:GetComponent("SkeletonAnimation")
        effect_mat = Util.GetMaterialOnSkeletonAnimation(anim, "effect_dwsg_Material")
        if effect_mat then
            effect_mat:SetFloat("_StencilComp", 8)
        end

        effect_mat2 = Util.GetMaterialOnSkeletonAnimation(anim, "effect_dwsg_Material-Additive")
        if effect_mat2 then
            effect_mat2:SetFloat("_StencilComp", 8)
        end

    end
    this.addEvent();
    --if isOpenUI(PanelNames.UICity) and not isOpenUI(PanelNames.UIChatPanel) and not isOpenUI(PanelNames.UIRanking) and not isOpenUI(PanelNames.UIGuildPanel)  and not isOpenUI(PanelNames.UIGuildRecommond) then
    if isInCity and not isOpenUI(PanelNames.UIGuild) then
        this.isInCityController.selectedIndex = 1;
    else
        this.isInCityController.selectedIndex = 0;
    end
    if OtherData and OtherData.data then
        this.Fresh_MyFriends()
        this.SetInfo(OtherData);

        this.showPetInfo()
    end

end

function UIPlayerShow.OnEnable()
    this.LocalListenEvent();

end

function UIPlayerShow.OnDisable()
    this.LocalCloseEvent();
    this.removePetModel()
    this.removeEvent()
    this.isload = false
end

function UIPlayerShow.OnDestroy()
    UIPlayerShow.ClearMaterial()
    if this.isNeedRemovePackage and UIPackage.GetById("FUI/Emoji") then
        UIPackage.RemovePackage("FUI/Emoji")
    end
end

function UIPlayerShow.addEvent()
    btnback.onClick:Add(this.OnCloseClick);
    btnpvchat.onClick:Add(this.onClickChat);
    btnCopy.onClick:Add(this.onCopyClick);
    btnaddFriend.onClick:Add(this.onClickAddFriend);
    btnBattle.onClick:Add(this.onClickBattle)
    this.Btn_BGClose.onClick:Add(this.OnCloseClick)
    this.Btn_PetMating.onClick:Add(this.OnClickPetMating)
    this.Btn_ShowPetInfo.onClick:Add(this.OnClickShowPetInfo)

    this.emojiList.onClickItem:Add(this.onClickEmojiList);

    btn_membershipapplication.onClick:Add(this.setChairman);
    btn_amendmentnotice.onClick:Add(this.setViceChairman);
    btn_Informationsettings.onClick:Add(this.setMember);
    btn_BlackList.onClick:Add(this.onClick_black)
    btn_quittheguild.onClick:Add(this.quitMember);
    this.btnPlayerkick.onClick:Add(this.quitMember);
    btn_blackbackground.onClick:Add(this.hideSettingGuildMember);
    btnGuildSetting.onClick:Add(this.showSettingGuildMember);

    ListenEvent(Config.EventType.ShowTitle, this.setShowTitle);
    ListenEvent(Config.EventType.RefreshOtherPetInfo, this.onRefreshOtherPetInfo)
    ListenEvent(Config.EventType.Fresh_MyFriends, this.Fresh_MyFriends)
    ListenEvent(Config.EventType.FriendCompeteBattle, this.OpenFriendCompeteBattle)
    ListenEvent(Config.EventType.Union_KickMember_S2C, this.kickMember);
    ListenEvent(Config.EventType.Union_ModifyJMemberJob_S2C, this.modifyMemberJob);
    ListenEvent(Config.EventType.Black_add_refresh, this.refreshBlack)
end

function UIPlayerShow.removeEvent()
    btnback.onClick:Clear();
    CloseEvent(Config.EventType.ShowTitle, this.setShowTitle);
    CloseEvent(Config.EventType.RefreshOtherPetInfo, this.onRefreshOtherPetInfo)
    CloseEvent(Config.EventType.Fresh_MyFriends, this.Fresh_MyFriends)
    CloseEvent(Config.EventType.FriendCompeteBattle, this.OpenFriendCompeteBattle)
    CloseEvent(Config.EventType.Union_KickMember_S2C, this.kickMember);
    CloseEvent(Config.EventType.Union_ModifyJMemberJob_S2C, this.modifyMemberJob);
    CloseEvent(Config.EventType.Black_add_refresh, this.refreshBlack)

    this.Btn_BGClose.onClick:Clear()
    this.btnBattle.onClick:Clear();
    this.Btn_PetMating.onClick:Clear()
    this.Btn_ShowPetInfo.onClick:Clear()
    this.btn_membershipapplication.onClick:Clear()
    this.btn_amendmentnotice.onClick:Clear()
    this.btn_Informationsettings.onClick:Clear()
    this.btn_quittheguild.onClick:Clear()
    this.btnPlayerkick.onClick:Clear()
    this.btn_blackbackground.onClick:Clear()
end

function UIPlayerShow.LocalListenEvent()

end

function UIPlayerShow.LocalCloseEvent()
end

function UIPlayerShow.OnCloseClick()
    if this.funcBack then
        this.funcBack();
    end
    this.removePetModel()
    managementController.selectedIndex = 0;
    closeUI(PanelNames.UIPlayerShow)

    UIPlayerShow.ClearMaterial()
end

function UIPlayerShow.ClearMaterial()
    if isOpenUI(PanelResNames.UIArenaRank) then
        if effect_mat then
            effect_mat:SetFloat("_StencilComp", 3)
        end
        if effect_mat2 then
            effect_mat2:SetFloat("_StencilComp", 3)
        end
    end
end

function UIPlayerShow.onClickChat()
    closeUI(PanelNames.UIPlayerShow);
    showUI(PanelNames.UIChatPanel);
    local data = {};
    data["head"] = tonumber(OtherData.data.pic);
    data["roleId"] = tostring(OtherData.data.playerId);
    data["roleName"] = OtherData.data.name;
    UIChatPanel.PrivateChatMsgPort(data);
end

function UIPlayerShow.onClickAddFriend()
    if tostring(OtherData.data.playerId) == logicMgr.HeroManager.GetRoleId() then
        UISysTips.AddMsg("不可添加自己为好友")
        return
    end
    if logicMgr.FriendManager.IsFriend(OtherData.data.playerId) then
        logicMgr.UIShowManager.ShowCommonConfirm(getLanguage("UIFriend_DeleteFriendTip"), nil, function()
            friendHandler.sendRemoveFriend(tostring(OtherData.data.playerId));
            this.OnCloseClick();
        end)
    else
        showUI(PanelNames.UIFriendApplyMessage, tostring(OtherData.data.playerId))
    end


    -- friendHandler.sendAddFriend(OtherData.data.playerId);
    --btnaddFriend.visible = false;
end

function UIPlayerShow.onCopyClick()
    UnityEngine.GUIUtility.systemCopyBuffer = heroID.text
    UISysTips.AddMsg(getLanguage("CopySuccess"))
end

function UIPlayerShow.setShowTitle(msg)
    for i = 1, #titles do
        local controller = titles[i]:GetController("show");
        local id = msg.showList[i];
        if id ~= nil then
            controller.selectedIndex = 1;
            titles[i]:GetChild("icon").url = "ui://ICONAtlas/" .. G.dataTable["t_medal"][tostring(id)].f_MedalPic;
            gameObject:GetChild("Badge" .. i .. "Title").text = getLanguage(G.dataTable["t_medal"][tostring(id)].f_MedalName);
        else
            controller.selectedIndex = 0;
            gameObject:GetChild("Badge" .. i .. "Title").text = "未展示";
        end
    end
end

function UIPlayerShow.ResetFormation()
    for i = 1, 5 do
        local indexFormObj = heroFormObj[i]
        local controller = indexFormObj:GetController("state");
        controller.selectedIndex = 0;
        if (UIPlayerShow.sendForm[i] ~= "0") then
            local pData = UIPlayerShow.sendForm[i];
            local ctrlItem = CtrlManager.GetCtrl(PanelNames.HeadRectBItem);
            if (pData ~= nil and ctrlItem) then
                local obj  = indexFormObj:GetChild("hero")
                controller.selectedIndex = 1;
                pData.notShowNum = true;
                obj.onClick:Clear()
                obj.onClick:Add(function()
                    if tostring(OtherData.data.playerId) == logicMgr.HeroManager.GetRoleId() then
                        UISysTips.AddMsg("当前玩家是自己")
                        return
                    end
                    showUI(PanelNames.UIOtherHeroInfo,tostring(OtherData.data.playerId),pData.partnerId)
                end)
                pData.halfIcon = logicMgr.SkinManager.GetHeroBIconBySkinId(pData.useSkin, pData.partnerModelId)
                if pData ~= nil then
                    if pData["faction"] == nil then
                        pData["faction"] = logicMgr.HeroManager.GetHeroFactionType(pData.partnerModelId)
                    end
                end
                ctrlItem.initData(obj, pData);
            end
        end
        --if (UIPlayerShow.sendForm[i] ~= nil) then
        --
        --    local pData = UIPlayerShow.sendForm[i]
        --    if (pData ~= nil) then
        --        local indexFormObj = heroFormObj[i]
        --        controller.selectedIndex = 1;
        --        --icon.gameObject:SetActive(true);
        --        local icon = indexFormObj:GetChild("heropo"):GetChild("icon");
        --        indexFormObj:GetChild("lvtext").text = logicMgr.HeroManager.starToShow(pData.star);
        --        indexFormObj:GetChild("level").text = string.format(getLanguage("Level"), pData.level);
        --        local temphero = logicMgr.HeroManager.getHeroDatabyModelId(pData.partnerModelId,true);
        --        icon.url = "ui://HalfBodyAtlas/" .. temphero.halfIcon;
        --        local vocationIcon = indexFormObj:GetChild("vocationIcon");
        --        vocationIcon.url = "ui://ICONAtlas/" .. EnumConst.HeroTypeIcon[temphero.type];
        --        local HighStar = 0;
        --for i = 1, 6 do
        --    local popStarObj = indexFormObj:Find("heroPobg/star" .. i):GetComponent("Image");
        --    if (i > tempStar) then
        --        popStarObj.gameObject:SetActive(false);
        --    else
        --        HighStar = HighStar + 1;
        --        popStarObj.gameObject:SetActive(true);
        --        popStarObj.fillAmount = 1;
        --    end
        --end
        --if (tempStar ~= 6 and (tempStar - HighStar == 0.5)) then
        --    local halfStar = indexFormObj:Find("heroPobg/star" .. (HighStar + 1)):GetComponent("Image");
        --    halfStar.gameObject:SetActive(true);
        --    halfStar.fillAmount = 0.5;
        --end
        --    end
        --else
        --    local controller = indexFormObj:GetController("state");
        --    local indexFormObj = heroFormObj[i]
        --    controller.selectedIndex = 0;
        --end
    end
end

function UIPlayerShow.SetInfo(v)
    if (v == nil) then
        this.ResetFormation();
        return
    end
    local roledata = v.data
    if roledata == nil then
        this.OnCloseClick();
        return ;
    end
    if tostring(OtherData.data.playerId) == logicMgr.HeroManager.GetRoleId() then
        this.isMeController.selectedIndex = 1;
    else
        this.isMeController.selectedIndex = 0;
    end
    TitleHandler.SendShowTitle(OtherData.data.playerId);

    if roledata.formation ~= nil then
        UIPlayerShow.sendForm = { };
        for i = 1, #roledata.formation do
            local indexherodata = roledata.formation[i]
            if (indexherodata ~= nil) then
                UIPlayerShow.sendForm[i] = indexherodata
            end
        end
    end
    heroName.text = roledata.name;
    heroLevel.text = roledata.level;
    heroPower.text = getNumString(toNumber(tostring(roledata.sumPower)))
    heroLove.text = roledata.watch;
    heroID.text = tostring(roledata.playerId);
    heroSex.selectedIndex = roledata.sex
    local severData = logicMgr.LoginManager.GetServerInAll(roledata.serverId) --logicMgr.LoginManager.GetLoginRecordIPInfo();
    if severData ~= nil then
        serverName.text = severData[Server_ENU_INDEX.NAME];
    end
    local image = logicMgr.SkinManager.GetHeroIconBySkinId(roledata.pic);

    local iconHead = headIcon:GetChild("head"):GetChild("HeadIcon");
    local iconFrame = headIcon:GetChild("frame");
    iconFrame.url = "ui://ICONAtlas/" .. roledata.frame;
    iconHead.url = image;
    --UIComponentInterface:SetPlayerIcon(nil,nil,nil,nil,{head=headIcon,favorLv=roledata.headPartnerFavorLv})
    this.ResetFormation();

    this.updateGuildInfo();
end

function this.updateGuildInfo()
    local selfPlayerId = logicMgr.HeroManager.GetRoleInfo().playerId;
    local selfTitleCfg = logicMgr.GuildManager.getUnionTitleCfgByPlayerId(selfPlayerId);
    local titleCfg = logicMgr.GuildManager.getUnionTitleCfgByPlayerId(OtherData.data.playerId);
    local unionName = logicMgr.GuildManager.getUnionName();
    if not titleCfg and OtherData.data.unionMember then
        titleCfg = G.dataTable["t_guildtitle"][tostring(OtherData.data.unionMember.jobId)];
        unionName = OtherData.data.unionMember.unionName;
    end
    memberTypeController.selectedIndex = 0;
    memberType1Controller.selectedIndex = 0;
    --btnGuildSetting.visible = false;
    this.btnPlayerkick.visible = true;
    if selfTitleCfg and OtherData.data.unionMember and OtherData.data.unionMember.unionId == logicMgr.GuildManager.getUnionId() then
        if logicMgr.GuildManager.isViceChairman(selfTitleCfg.f_TitleId) then
            memberTypeController.selectedIndex = 1;
            memberType1Controller.selectedIndex = 1;
            if titleCfg and logicMgr.GuildManager.isChairman(titleCfg.f_TitleId) then
                this.btnPlayerkick.visible = false;
            end
        elseif GuildManager.isChairman(selfTitleCfg.f_TitleId) then
            memberTypeController.selectedIndex = 2;
            memberType1Controller.selectedIndex = 2;
            --if OtherData.data.unionMember then
            --    btnGuildSetting.visible = OtherData.data.unionMember.unionId == GuildManager.getUnionId() and true or false;
            --else
            --    btnGuildSetting.visible = false;
            --end
        end
    end

    positionController.selectedIndex = 0;

    if not titleCfg then
        this.text_guildName.text = '';
        this.text_position.text = '';
    else
        this.text_guildName.text = unionName;
        this.text_position.text = getLanguage("f_GuildTitleName1");
        if logicMgr.GuildManager.isViceChairman(titleCfg.f_TitleId) then
            positionController.selectedIndex = 1;
            this.text_position.text = getLanguage("f_GuildTitleName2");
        elseif logicMgr.GuildManager.isChairman(titleCfg.f_TitleId) then
            this.text_position.text = getLanguage("f_GuildTitleName3");
            this.hideSettingGuildMember();
        end
    end
end

function this.onRefreshOtherPetInfo()
    this.showPetInfo()
end
function this.showPetInfo()
    local _petName = ""
    if PetManager.OtherPetInfo and table.getn(PetManager.OtherPetInfo) > 0 then
        _petName = PetManager.OtherPetInfo.petName
        this.showPetModel()
    end
    this.Txt_PetName.text = _petName
end
function this.OnClickPetMating()
    if tostring(OtherData.data.playerId) == logicMgr.HeroManager.GetRoleId() then
        UISysTips.AddMsg("当前和自己拟变")
        return
    end
    if PetManager.OtherPetInfo and table.getn(PetManager.OtherPetInfo) > 0 then
        if #PetManager.PetInfoList == 0 then
            UISysTips.AddMsg(getLanguage("PetMating_DoNotHaveAnyPet"))
        elseif table.getn(PetManager.myApply) > 0 and PetManager.OtherPetInfo.petId ~= PetManager.myApply.templatePetInfo.petId then
            UISysTips.AddMsg(getLanguage("PetMating_CannotMultipleApply"))
        elseif FriendManager.GetMyFriend(OtherData.data.playerId) == nil then
            --要先添加好友才能进行拟变
            UISysTips.AddMsg(getLanguage("PetApply_NoFriends"));
        else
            showUI(PanelNames.Page_PetApplyMyRequest)
        end
    else
        UISysTips.AddMsg(getLanguage("PetMating_CurrentPlayerNoPet"))
    end
end

--显示宠物模型
function this.removePetModel()
    if this.PetModelGO then
        destroyImmediate(this.PetModelGO)
    end
    this.PetModelGO = nil

end
function this.showPetModel()
    local _petInfo = PetManager.OtherPetInfo
    if _petInfo and #_petInfo.genes == PetManager.PetPart.Ornament then
        local _petModelInfo = {}
        _petModelInfo.parentGO = this.Model_Pet
        _petModelInfo.petId = _petInfo.petId
        if this.PetModelGO then
            _petModelInfo.modelGO = this.PetModelGO
            _petModelInfo.modelWrapper = this.goWrapper
            PetManager.PetModelRefresh(_petModelInfo, _petInfo.genes, true)
        else
            this:removePetModel()
            resMgr:LoadModelPrefab(PetManager.PetModelPrefab, function(go)
                this.PetModelGO = newObject(go)

                local com = this.PetModelGO:GetComponent("SkeletonGraphic")

                if this.PetModelGO and com then
                    com.material = resMgr.Pet_Copy_Mat
                    com.material:SetFloat("_StencilComp",8)
                    com.material:SetFloat("_Stencil",1);
                end
                
                local _modelWrapper = this.goWrapper
                this.goWrapper = GoWrapper.New()
                _petModelInfo.modelGO = this.PetModelGO
                _petModelInfo.modelWrapper = this.goWrapper
                PetManager.PetModelFirstSet(_petModelInfo, _petInfo.genes, true, Vector3.New(0, 0, 0), Vector3.New(0.7, 0.7, 1))
                if _modelWrapper then
                    _modelWrapper:Dispose()
                end
            end)
        end
    end
end
function this.OnClickShowPetInfo()
    local _petInfo = PetManager.OtherPetInfo
    if table.getn(_petInfo) > 0 then
        showUI(PanelNames.Page_PetInfoDetail)
    end
end

function this.onClickEmojiList(context)
    local nowTime = HelperFunc.GetServerTime();
    if nowTime - logicMgr.ChatManager.getSendEmojiTime() <= HelperFunc.GetGlobalNumVlue(189) then
        UISysTips.AddMsg(getLanguage("Sys_MsgSayHelloCD"));
        return ;
    end
    logicMgr.ChatManager.setSendEmojiTime(nowTime);
    this.showEmojiController.selectedIndex = 0;
    local go = context.data
    --local index = this.emojiList:GetChildIndex(go);
    local roledata = OtherData.data;
    --[[ local msgtbl = {};
     msgtbl.Channel = Config.MsgChannel.Person;
     msgtbl.Message = "h-e^l-l^o";
     msgtbl.head = logicMgr.HeroManager.GetRoleIcon();
     msgtbl.level = tonumber(go.name)
     msgtbl.roleId = logicMgr.HeroManager.GetRoleId();
     msgtbl.roleName = logicMgr.HeroManager.GetRoleName();
     msgtbl.unRead = true;
     msgtbl.time = HelperFunc.GetServerTime();
     msgtbl.PlayerId = tostring(roledata.playerId);
     msgtbl.PlayerName = roledata.name;
     msgtbl.PlayerHead = roledata.pic;
     logicMgr.ChatManager.addSendEmojiId(tonumber(go.name));
     FireEvent(Config.EventType.RefreshSendEmoji);
     chatHandler.sendPrivateMsg(msgtbl.PlayerId, msgtbl);]]

    chatHandler.SendHello(tonumber(go.name), tostring(roledata.playerId), roledata.name, roledata.pic)
    this.OnCloseClick();
end
function this.Fresh_MyFriends()
    if logicMgr.FriendManager.IsFriend(OtherData.data.playerId) then
        this.ctrlFriend.selectedIndex = 1
    else
        this.ctrlFriend.selectedIndex = 0
    end
end
function this.onClickBattle()
    if tostring(OtherData.data.playerId) == logicMgr.HeroManager.GetRoleId() then
        UISysTips.AddMsg("当前与玩家自己进行切磋")
        return
    end
    friendHandler.ReqFriendCompeteInfo(OtherData.data.playerId)
end
function this.OpenFriendCompeteBattle(msg)
    this.OnCloseClick();
    local param = {};
    --param.playerId = 0;
    local info = logicMgr.FriendManager.GetFriendCompeteBattleInfo()
    param.power = 0;
    param.supSkillId = info.supportSkill;
    param.wins = info.winTimes;
    param.competeTimes = info.competeTimes;
    --param.type = EnumConst.FormationType.ArenaDef;
    logicMgr.FriendManager.SetFriendCompeteBattleType(EnumConst.FightTypeConst.FriendCompeteBattle)
    showUI(PanelNames.UIBattleTeam, EnumConst.FightTypeConst.FriendCompeteBattle, param, function(formations)

        local flag = true;
        if formations[1] ~= nil then
            for i = 1, #formations[1] do
                if formations[1][i] ~= nil and tonumber(tostring(formations[1][i])) > 0 then
                    flag = false;
                    break ;
                end
            end
        end
        if flag then
            UISysTips.AddMsg("需要上阵至少一名英雄");
        else
            local supSkills = logicMgr.SkillManager.getSupSkillInfo();
            local supSkillId = 0;
            for i = 1, #supSkills do
                if supSkills[i].isUse == 1 then
                    supSkillId = tostring(supSkills[i].skillId);
                end
            end
            local info = logicMgr.FriendManager.GetFriendCompeteBattleInfo()
            friendHandler.ReqFriendCompeteBattle(info.friendId, formations[1], supSkillId)
            BattlePlaybackManager.setBattleBackFunc(function()
                if this.funcBattleBack then
                    this.funcBattleBack()
                end ;
            end)
        end
    end, function()
        --showCtrl.selectedPage = "show";
    end)

end

function this.kickMember()
    UISysTips.AddMsg(getLanguage("GuildInvestment_1086"));
    this.OnCloseClick()
    --this.updateGuildInfo();
    --managementController.selectedIndex = 0;
end

function this.modifyMemberJob()
    UISysTips.AddMsg(getLanguage("GuildInvestment_1087"));
    this.updateGuildInfo();
end

function this.showSettingGuildMember()
    managementController.selectedIndex = 1;
end

function this.hideSettingGuildMember()
    managementController.selectedIndex = 0;
end

function this.setChairman()
    local pop = CtrlManager.GetCtrl(PanelNames.UICommonPop);
    pop.Init("41", function(b)
        if b then
            unionHandler.reqModifyJMemberJob(logicMgr.GuildManager.getUnionId(), OtherData.data.playerId, logicMgr.GuildManager.JOB_CHAIRMAN_ID);
            GuildManager.SetChangeJobInfo(logicMgr.GuildManager.JOB_CHAIRMAN_ID, OtherData.data.playerId)
        end
    end);
end

function this.setViceChairman()
    if logicMgr.GuildManager.getRemainViceChairmanCnt() <= 0 then
        UISysTips.AddMsg(getLanguage("GuildInvestment_1088"));
        return ;
    end
    local pop = CtrlManager.GetCtrl(PanelNames.UICommonPop);
    pop.Init("42", function(b)
        if b then
            unionHandler.reqModifyJMemberJob(logicMgr.GuildManager.getUnionId(), OtherData.data.playerId, logicMgr.GuildManager.JOB_VICECHAIRMAN_ID);
            GuildManager.SetChangeJobInfo(logicMgr.GuildManager.JOB_VICECHAIRMAN_ID, OtherData.data.playerId)
        end
    end);
end

function this.setMember()
    local pop = CtrlManager.GetCtrl(PanelNames.UICommonPop);
    pop.Init("44", function(b)
        if b then
            unionHandler.reqModifyJMemberJob(logicMgr.GuildManager.getUnionId(), OtherData.data.playerId, logicMgr.GuildManager.JOB_MEEMBER_ID);
            GuildManager.SetChangeJobInfo(logicMgr.GuildManager.JOB_MEEMBER_ID, OtherData.data.playerId)
        end
    end);
end

function this.quitMember()
    local pop = CtrlManager.GetCtrl(PanelNames.UICommonPop);
    pop.Init("43", function(b)
        if b then
            logicMgr.GuildManager.remove_playerid = tostring(OtherData.data.playerId)
            unionHandler.reqKickMemberInfo(OtherData.data.playerId);
        end
    end);
end

function this.onClick_black()
    if logicMgr.FriendManager.IsFriend(OtherData.data.playerId) then
        local pop = CtrlManager.GetCtrl(PanelNames.UICommonPop);
        pop.Init("114", function(b)
            if b then
                
                this.blackOperate()
            end
        end);
    else
        this.blackOperate()
    end
end

function this.blackOperate()
    local b = logicMgr.FriendManager.IsInBlack(OtherData.data.playerId)
    if b then
        friendHandler.ReqBlackPLayer(OtherData.data.playerId, 2)
    else
        local max,cur = FriendManager.GetBlackMax()
        if cur >= max then
            UISysTips.AddMsg(getLanguage("ErrorCode_5130"))
        else
            friendHandler.ReqBlackPLayer(OtherData.data.playerId, 1)
            if logicMgr.FriendManager.IsFriend(OtherData.data.playerId) then
                friendHandler.sendRemoveFriend(OtherData.data.playerId)
            end
        end
    end
end

function this.refreshBlack()
    if logicMgr.FriendManager.IsInBlack(OtherData.data.playerId) then
        txt_blackTxt.text = getLanguage("BlackListTips2")
    else
        txt_blackTxt.text = getLanguage("CommonPop_Title114")
    end
end

return UIPlayerShow;